<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/9/9
 * Time: 上午11:39
 */

namespace Home\Model;
use Think\Model;

class ForumAttachmentModel extends Model
{
    protected $tableName = 'forum_attachment';
    protected $trueTableName    =   'ivf_forum_attachment';
    protected $connection       =   'BBS_DB_CONFIG';


    public static function getAttachmentByVid($id)
    {
        $object = new static();
        $attachmentTable = $object->where(array('tid' => $id))->select();
        $attachmentImage = array();
        if($attachmentTable)
        {
            $tableID = array();
            foreach ($attachmentTable as $attachment) {
                $tableID[$attachment['tableid']][] = $attachment['aid'];
            }
            foreach ($tableID as $key => $item) {
                $condition = array(
                    'aid' => array('in',$item),
                    'isimage' => 1
                );
                $attachment = $object->table('ivf_forum_attachment_' . $key)->field(array('isimage','attachment'))->where($condition)->select();
                if($attachment)
                {
                    foreach ($attachment as $index => $attach) {
                            $attachmentImage[] = 'http://bimg.snsnb.com/data/attachment/forum/' . $attach['attachment'];
                    }
                }
            }
        }
        return $attachmentImage;
    }

}